package com.cn.wanxi.servlet;

import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.model.ProductModel;
import com.cn.wanxi.model.ProductTypeModel;
import com.cn.wanxi.service.CompanyService;
import com.cn.wanxi.service.NavService;
import com.cn.wanxi.service.ProductService;
import com.cn.wanxi.service.ProductTypeService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/product")
public class ProductServlet extends HttpServlet {
    CompanyService companyService = new CompanyService();
    NavService navService = new NavService();
    ProductTypeService productTypeService = new ProductTypeService();
    ProductService productService = new ProductService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CompanyModel companyModel = companyService.getCompany();
        List<NavModel> navList = navService.getNavList();
        List<ProductTypeModel> productTypeList = productTypeService.getProductTypeList();
        List<ProductModel> productList = productService.getProductList();
        req.setAttribute("company", companyModel);
        req.setAttribute("nav",navList);
        req.setAttribute("productTypes",productTypeList);
        req.setAttribute("products",productList);
        req.getRequestDispatcher("/jsp/product.jsp").forward(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
